package com.example.weatherpiano.Fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.weatherpiano.DAO.City;
import com.example.weatherpiano.DAO.CurrentWeather;
import com.example.weatherpiano.R;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link city_weather#newInstance} factory method to
 * create an instance of this fragment.
 */
public class city_weather extends Fragment {

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_TEMP = "param1";
    private static final String ARG_CITY = "param2";
    private static final String ARG_WEATHER = "param3";


    // TODO: Rename and change types of parameters
    private String temp;
    private String city;
    private String weather;
    private View rootView;

    public city_weather() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @return A new instance of fragment city_weather.
     */
    // TODO: Rename and change types and number of parameters
    public static city_weather newInstance(City city) {

        city_weather fragment = new city_weather();
        Bundle args = new Bundle();
        args.putString(ARG_TEMP, city.getCurrent_weather().getCurrent_temp().toString());
        args.putString(ARG_CITY, city.getCity_name());
        args.putString(ARG_WEATHER, city.getCurrent_weather().getWeather());

        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            temp = getArguments().getString(ARG_TEMP);
            city = getArguments().getString(ARG_CITY);
            weather = getArguments().getString(ARG_WEATHER);

        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        if (rootView == null) {
            rootView = inflater.inflate(R.layout.fragment_city_weather, container, false);
        }
        initView();
        return rootView;
    }



    private void initView() {
        TextView temp_tv = rootView.findViewById(R.id.temp);
        TextView weather_tv = rootView.findViewById(R.id.weather);

        temp_tv.setText(temp);
        weather_tv.setText(weather);
    }
}